<template>
<div id="showGoods">
        <button @click="upchange">升序</button>
        <button @click="downchange">降序</button>
        <div>
				<!-- 商品组件-->
        <Prolist :prolist = "prolist"/>
		</div>
 </div>
</template>
<script>
import Prolist from '@/components/Prolist'
export default {
  components: {
    Prolist
  },
  data: {
    listinfo: null; //获取到后台提供的值
  },
  created () {
    kindAll().then(data => {
      this.kindList = data.data
      this.listinfo = this.kindList[0].data
    })
  }
  methods: {
   	upchange() {
   	// 写法一
    this.listinfo.sort((a,b)=>{
      // 排序基于的数据
      return a.price - b.price;
      })
    },
    downchange() {
      //写法二
      function sortData(a, b) {
        return b.price - a.price;
      }
      this.listinfo.sort(sortData);
    }
  }
}
</script>
